#include<stdio.h>
int main()
{
	char arr[] = "123";
	int a = atoi(arr);
	printf("%d", a);
	return 0;
}

#include<stdio.h>
int main()
{
	unsigned char a = -2;
	printf("%d", a);
}

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int a = 0;
	while (scanf("%d", &a) == 1)
	{
		int arr[31] = { 0 };
		int i = 0;
		arr[0] = 0, arr[1] = 1;
		for (i = 1;i < 30; i++)
		{
			arr[i + 1] = arr[i] + arr[i - 1];
		}
		for (i = 1; i < 31; i++)
		{
			if (arr[i] == a)
			{
				printf("0\n");
				break;
			}
			if (arr[i] > a)
			{
				if ((arr[i] - a) <= (a - arr[i - 1]))
				{
					printf("%d\n", arr[i] - a);
					break;
				}
				else
				{
					printf("%d\n", a - arr[i-1]);
					break;
				}
				}
		}
	}
}